{% extends "../templates/ajax/main_content_base.html" %} 
{% block intro %}{% endblock %}
{% block page_name %}homework_list{% endblock %}
{% block content %}


<div class="content-box">
	<div class="content-box-header">
		<h3>{{homework.name}}</h3>
	</div>
	<!-- End .content-box-header -->

	<div class="content-box-content">

		<div class="tab-content default-tab">

			<p>
			<h5 style="display:inline" >截止日期：</h5><span style="font-weight:bold;font-size:16px;color:red">{{homework.deadline|date:"Y年n月d日 ,G:i"}}</span>
			</p>
			<p>
			<h5  style="display:inline">发布日期：</h5><span>{{homework.pub_date|date:"Y年n月d日 ,G:i"}}</span>
			</p>
			<p>
			<h5 style="display:inline">上次更新：</h5><span>{{homework.last_updated_time|date:"Y年n月d日 ,G:i"}}</span>
			</p>
			<p>
				<h5 style="display:inline">作业类型：</h5>
				<span>
				{% ifequal homework.type 'personal'%}
					个人作业
				{% else %}
					小组作业
				{% endifequal %}
				</span>
			</p>
			
			<p>

				<div>
				{{homework.content|safe}}
				</div>
			</p>
		</div>
		<!-- End #tab3 -->

	</div>
	<!-- End .content-box-content -->

</div>
<div class="content-box">
	<div class="content-box-header">
		<h3>我要评论&acute;</h3>
	</div>
	<!-- End .content-box-header -->
	<a id="show-reply-link" onclick="show_post_reply('');" name='' href="javascript:void(0);" class="show-reply-link">发表评论</a>
	<div id="post-reply-" class="post-reply">
	</div>
	<div class="content-box-content">

		<div class="tab-content default-tab">
			<form style="display:none" id="create-comment-form" action="create_comment" method="post">

				<fieldset>
					<!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->

					<input id='homework' name="homework" type="hidden" value="{{homework.id}}"/>
					<input id='parent_comment' name="parent_comment" type="hidden" value=""/>
					<p>
						<label>评论内容</label>
						<textarea class="text-input textarea large-input required" id="comment-content"
							name="content" cols="79" rows="3"></textarea>
						<br />
					</p>

					<p>
						<input onclick="$('#file').uploadifyUpload();return false" class="button" type="submit" value="评论" />
					</p>

				</fieldset>

				<div class="clear"></div>
				<!-- End .clear -->

			</form>
			
		</div>
		<!-- End #tab3 -->

	</div>
	<!-- End .content-box-content -->

</div>
<!-- End .content-box -->
<div class="content-box">
	<div class="content-box-header">
		<h3>评论</h3>
	</div>
	<!-- End .content-box-header -->

	<div class="content-box-content">

		<div class="tab-content default-tab">
			<div id='comment-list-content'>
	
			</div>
			<div class="clear"></div>

			

			
		</div>
		<!-- End #tab3 -->

	</div>
	<!-- End .content-box-content -->

</div>
<!-- End .content-box -->

<style>
	.replies
	{
		margin-left:20px;
	}
</style>
<script type="text/javascript" src="resources/scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="resources/scripts/jquery.form.js"></script>
<script type="text/javascript" src="resources/scripts/jquery.boxy.js"></script>
<script type="text/javascript">
var template;
$.get('template',
		{'template':'ajax/comment.html'},
		function(data) {
			template = data
	 get_comments()

	});

function get_comments()
{
	$.getJSON('get_comments', 
				{'homework':'{{homework.id}}'},
				function(comments) {
					$.each(comments.comments,function(index,comment){
						//alert(2);
						insert_comment(comment)
						
					});


				});
}
function insert_comment(comment)
{	
	comment_div = template.replace('comment.content',comment.content)
	  .replace(/comment.author/g,comment.author)
	  .replace(/comment.pub_date/g,comment.pub_date)
	  .replace(/comment.id/g,comment.id)
	if(comment.parent_comment)
		$('#replies-'+comment.parent_comment).prepend($(comment_div).show('fast') )
	else
		$('#comment-list-content').prepend($(comment_div).show('fast'))
	
	$('#show-reply-link-'+comment.id).click(function(){
		show_post_reply(comment.id)
	})
	
}
function show_post_reply(id)
{	$('#create-comment-form').hide()
	$('#post-reply-'+id).append($('#create-comment-form').show('fast'))
	$('#parent_comment').val(id)
}
$('#create-comment-form').ajaxForm({
    // dataType identifies the expected content type of the server response
    dataType: 'json',

    // success identifies the function to invoke when the server response
    // has been received
    success:function(json)
    {
    	if(json.error)
    			Boxy.alert("评论错误，请检查您的信息\n"+json.error_type+json.error, function() {}, {title: '错误'});
    	else
    		{
    		$('#create-comment-form').hide('fast')
    			$('#comment-content').text('')
				insert_comment(json.comments[0])
    		}
    }
});
</script>
{% endblock %}
